home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / intsdkss.lha / include / sys / socketvar.h < prev    next >
C/C++ Source or Header  |  1996-04-09  |  6KB  |  166 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that this notice is preserved and that due credit is given
  7.  * to the University of California at Berkeley. The name of the University
  8.  * may not be used to endorse or promote products derived from this
  9.  * software without specific prior written permission. This software
  10.  * is provided ``as is'' without express or implied warranty.
  11.  *
  12.  *    @(#)socketvar.h 7.3 (Berkeley) 12/30/87
  13.  */
  14.  
  15. /*
  16.  * Kernel structure per socket.
  17.  * Contains send and receive buffer queues,
  18.  * handle on protocol and pointer to protocol
  19.  * private data and error information.
  20.  */
  21. struct socket {
  22.     short    so_type;        /* generic type, see socket.h */
  23.     short    so_options;        /* from socket call, see socket.h */
  24.     short    so_linger;        /* time to linger while closing */
  25.     short    so_state;        /* internal state flags SS_*, below */
  26.     caddr_t so_pcb;         /* protocol control block */
  27.     struct    protosw *so_proto;    /* protocol handle */
  28. /*
  29.  * Variables for connection queueing.
  30.  * Socket where accepts occur is so_head in all subsidiary sockets.
  31.  * If so_head is 0, socket is not related to an accept.
  32.  * For head socket so_q0 queues partially completed connections,
  33.  * while so_q is a queue of connections ready to be accepted.
  34.  * If a connection is aborted and it has so_head set, then
  35.  * it has to be pulled out of either so_q0 or so_q.
  36.  * We allow connections to queue up based on current queue lengths
  37.  * and limit on number of queued connections for this socket.
  38.  */
  39.     struct    socket *so_head;    /* back pointer to accept socket */
  40.     struct    socket *so_q0;        /* queue of partial connections */
  41.     struct    socket *so_q;        /* queue of incoming connections */
  42.     short    so_q0len;        /* partials on so_q0 */
  43.     short    so_qlen;        /* number of connections on so_q */
  44.     short    so_qlimit;        /* max number queued connections */
  45.     short    so_timeo;        /* connection timeout */
  46.     u_short so_count;        /* number of times socket is opened */
  47.     u_short so_error;        /* error affecting connection */
  48.     u_long    so_oobmark;        /* chars to oob mark */
  49.  
  50. /*
  51.  * Variables for task signalling.
  52.  */
  53.     struct Task *so_pgrp;        /* Task for signalling */
  54.     char    so_sigurg;        /* urgent signal bit for task */
  55.     char    so_sigio;        /* io signal bit for task */
  56.     short    so_pad;         /* for longword alignment */
  57. /*
  58.  * Variables for socket buffering.
  59.  */
  60.     struct    sockbuf {
  61.         u_long    sb_cc;        /* actual chars in buffer */
  62.         u_long    sb_hiwat;    /* max actual char count */
  63.         u_long    sb_mbcnt;    /* chars of mbufs used */
  64.         u_long    sb_mbmax;    /* max chars of mbufs to use */
  65.         u_long    sb_lowat;    /* low water mark (not used yet) */
  66.         struct    mbuf *sb_mb;    /* the mbuf chain */
  67.         struct    Task *sb_sel;    /* process selecting read/write */
  68.         short    sb_sigbit;    /* signal to send */
  69.         short    sb_timeo;    /* timeout (not used yet) */
  70.         short    sb_flags;    /* flags, see below */
  71.         short    sb_pad;     /* for longword alignment */
  72.     } so_rcv, so_snd;
  73. #ifndef SB_MAX
  74. #define SB_MAX        (64*1024)    /* max chars in sockbuf */
  75. #endif
  76. #define SB_LOCK     0x01        /* lock on data queue (so_rcv only) */
  77. #define SB_WANT     0x02        /* someone is waiting to lock */
  78. #define SB_WAIT     0x04        /* someone is waiting for data/space */
  79. #define SB_SEL        0x08        /* buffer is selected */
  80. #define SB_COLL     0x10        /* collision selecting */
  81.     long    so_stamp;        /* this is a socket */
  82. };
  83.  
  84. /*
  85.  * Socket state bits.
  86.  */
  87. #define SS_NOFDREF        0x001    /* no file table ref any more */
  88. #define SS_ISCONNECTED        0x002    /* socket connected to a peer */
  89. #define SS_ISCONNECTING     0x004    /* in process of connecting to peer */
  90. #define SS_ISDISCONNECTING    0x008    /* in process of disconnecting */
  91. #define SS_CANTSENDMORE     0x010    /* can't send more data to peer */
  92. #define SS_CANTRCVMORE        0x020    /* can't receive more data from peer */
  93. #define SS_RCVATMARK        0x040    /* at mark on input */
  94.  
  95. #define SS_PRIV         0x080    /* privileged for broadcast, raw... */
  96. #define SS_NBIO         0x100    /* non-blocking ops */
  97. #define SS_ASYNC        0x200    /* async i/o notify */
  98.  
  99.  
  100. /*
  101.  * Macros for sockets and socket buffering.
  102.  */
  103.  
  104. /* how much space is there in a socket buffer (so->so_snd or so->so_rcv) */
  105. #define sbspace(sb) \
  106.     (MIN((long)((sb)->sb_hiwat - (sb)->sb_cc),\
  107.      (long)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
  108.  
  109. /* do we have to send all at once on a socket? */
  110. #define sosendallatonce(so) \
  111.     ((so)->so_proto->pr_flags & PR_ATOMIC)
  112.  
  113. /* can we read something from so? */
  114. #define soreadable(so) \
  115.     ((so)->so_rcv.sb_cc || ((so)->so_state & SS_CANTRCVMORE) || \
  116.     (so)->so_qlen || (so)->so_error)
  117.  
  118. /* can we write something to so? */
  119. #define sowriteable(so) \
  120.     (sbspace(&(so)->so_snd) > 0 && \
  121.     (((so)->so_state&SS_ISCONNECTED) || \
  122.       ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0) || \
  123.      ((so)->so_state & SS_CANTSENDMORE) || \
  124.      (so)->so_error)
  125.  
  126. /* adjust counters in sb reflecting allocation of m */
  127. #define sballoc(sb, m) { \
  128.     (sb)->sb_cc += (m)->m_len; \
  129.     (sb)->sb_mbcnt += MSIZE; \
  130.     if ((m)->m_off > MMAXOFF) \
  131.         (sb)->sb_mbcnt += CLBYTES; \
  132. }
  133.  
  134. /* adjust counters in sb reflecting freeing of m */
  135. #define sbfree(sb, m) { \
  136.     (sb)->sb_cc -= (m)->m_len; \
  137.     (sb)->sb_mbcnt -= MSIZE; \
  138.     if ((m)->m_off > MMAXOFF) \
  139.         (sb)->sb_mbcnt -= CLBYTES; \
  140. }
  141.  
  142. /* set lock on sockbuf sb */
  143. #define sblock(sb) { \
  144.     while ((sb)->sb_flags & SB_LOCK) { \
  145.         (sb)->sb_flags |= SB_WANT; \
  146.         sleep((u_long)&(sb)->sb_flags, PZERO+1); \
  147.     } \
  148.     (sb)->sb_flags |= SB_LOCK; \
  149. }
  150.  
  151. /* release lock on sockbuf sb */
  152. #define sbunlock(sb) { \
  153.     (sb)->sb_flags &= ~SB_LOCK; \
  154.     if ((sb)->sb_flags & SB_WANT) { \
  155.         (sb)->sb_flags &= ~SB_WANT; \
  156.         wakeup((u_long)&(sb)->sb_flags); \
  157.     } \
  158. }
  159.  
  160. #define sorwakeup(so)    sowakeup((so), &(so)->so_rcv)
  161. #define sowwakeup(so)    sowakeup((so), &(so)->so_snd)
  162.  
  163. #ifdef KERNEL
  164. struct    socket *sonewconn();
  165. #endif
  166.